home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch19 / Solids.frm (.txt) < prev    next >
Visual Basic Form  |  1999-07-12  |  10KB  |  329 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSolids 
  3.    Caption         =   "Solids"
  4.    ClientHeight    =   2745
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   8520
  8.    KeyPreview      =   -1  'True
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   2745
  11.    ScaleWidth      =   8520
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.PictureBox picCanvas 
  14.       AutoRedraw      =   -1  'True
  15.       BackColor       =   &H00FFFFFF&
  16.       Height          =   1575
  17.       Index           =   3
  18.       Left            =   5160
  19.       ScaleHeight     =   -4
  20.       ScaleLeft       =   -2
  21.       ScaleMode       =   0  'User
  22.       ScaleTop        =   2
  23.       ScaleWidth      =   4
  24.       TabIndex        =   16
  25.       Top             =   1080
  26.       Width           =   1575
  27.    End
  28.    Begin VB.PictureBox picCanvas 
  29.       AutoRedraw      =   -1  'True
  30.       BackColor       =   &H00FFFFFF&
  31.       Height          =   1575
  32.       Index           =   4
  33.       Left            =   6840
  34.       ScaleHeight     =   -4
  35.       ScaleLeft       =   -2
  36.       ScaleMode       =   0  'User
  37.       ScaleTop        =   2
  38.       ScaleWidth      =   4
  39.       TabIndex        =   15
  40.       Top             =   1080
  41.       Width           =   1575
  42.    End
  43.    Begin VB.PictureBox picCanvas 
  44.       AutoRedraw      =   -1  'True
  45.       BackColor       =   &H00FFFFFF&
  46.       Height          =   1575
  47.       Index           =   2
  48.       Left            =   3480
  49.       ScaleHeight     =   -4
  50.       ScaleLeft       =   -2
  51.       ScaleMode       =   0  'User
  52.       ScaleTop        =   2
  53.       ScaleWidth      =   4
  54.       TabIndex        =   10
  55.       Top             =   1080
  56.       Width           =   1575
  57.    End
  58.    Begin VB.PictureBox picCanvas 
  59.       AutoRedraw      =   -1  'True
  60.       BackColor       =   &H00FFFFFF&
  61.       Height          =   1575
  62.       Index           =   1
  63.       Left            =   1800
  64.       ScaleHeight     =   -4
  65.       ScaleLeft       =   -2
  66.       ScaleMode       =   0  'User
  67.       ScaleTop        =   2
  68.       ScaleWidth      =   4
  69.       TabIndex        =   5
  70.       Top             =   1080
  71.       Width           =   1575
  72.    End
  73.    Begin VB.PictureBox picCanvas 
  74.       AutoRedraw      =   -1  'True
  75.       BackColor       =   &H00FFFFFF&
  76.       Height          =   1575
  77.       Index           =   0
  78.       Left            =   120
  79.       ScaleHeight     =   -4
  80.       ScaleLeft       =   -2
  81.       ScaleMode       =   0  'User
  82.       ScaleTop        =   2
  83.       ScaleWidth      =   4
  84.       TabIndex        =   2
  85.       Top             =   1080
  86.       Width           =   1575
  87.    End
  88.    Begin VB.Label lblSegments 
  89.       Height          =   255
  90.       Index           =   3
  91.       Left            =   5160
  92.       TabIndex        =   24
  93.       Top             =   600
  94.       Width           =   1575
  95.    End
  96.    Begin VB.Label lblPoints 
  97.       Height          =   255
  98.       Index           =   3
  99.       Left            =   5160
  100.       TabIndex        =   23
  101.       Top             =   360
  102.       Width           =   1575
  103.    End
  104.    Begin VB.Label lblVerify 
  105.       Height          =   255
  106.       Index           =   3
  107.       Left            =   5160
  108.       TabIndex        =   22
  109.       Top             =   840
  110.       Width           =   1575
  111.    End
  112.    Begin VB.Label Label1 
  113.       Caption         =   "Dodecahedron"
  114.       Height          =   255
  115.       Index           =   3
  116.       Left            =   5160
  117.       TabIndex        =   21
  118.       Top             =   120
  119.       Width           =   1575
  120.    End
  121.    Begin VB.Label Label1 
  122.       Caption         =   "Icosahedron"
  123.       Height          =   255
  124.       Index           =   4
  125.       Left            =   6840
  126.       TabIndex        =   20
  127.       Top             =   120
  128.       Width           =   1575
  129.    End
  130.    Begin VB.Label lblVerify 
  131.       Height          =   255
  132.       Index           =   4
  133.       Left            =   6840
  134.       TabIndex        =   19
  135.       Top             =   840
  136.       Width           =   1575
  137.    End
  138.    Begin VB.Label lblPoints 
  139.       Height          =   255
  140.       Index           =   4
  141.       Left            =   6840
  142.       TabIndex        =   18
  143.       Top             =   360
  144.       Width           =   1575
  145.    End
  146.    Begin VB.Label lblSegments 
  147.       Height          =   255
  148.       Index           =   4
  149.       Left            =   6840
  150.       TabIndex        =   17
  151.       Top             =   600
  152.       Width           =   1575
  153.    End
  154.    Begin VB.Label lblSegments 
  155.       Height          =   255
  156.       Index           =   2
  157.       Left            =   3480
  158.       TabIndex        =   14
  159.       Top             =   600
  160.       Width           =   1575
  161.    End
  162.    Begin VB.Label lblPoints 
  163.       Height          =   255
  164.       Index           =   2
  165.       Left            =   3480
  166.       TabIndex        =   13
  167.       Top             =   360
  168.       Width           =   1575
  169.    End
  170.    Begin VB.Label lblVerify 
  171.       Height          =   255
  172.       Index           =   2
  173.       Left            =   3480
  174.       TabIndex        =   12
  175.       Top             =   840
  176.       Width           =   1575
  177.    End
  178.    Begin VB.Label Label1 
  179.       Caption         =   "Octahedron"
  180.       Height          =   255
  181.       Index           =   2
  182.       Left            =   3480
  183.       TabIndex        =   11
  184.       Top             =   120
  185.       Width           =   1575
  186.    End
  187.    Begin VB.Label Label1 
  188.       Caption         =   "Cube"
  189.       Height          =   255
  190.       Index           =   1
  191.       Left            =   1800
  192.       TabIndex        =   9
  193.       Top             =   120
  194.       Width           =   1575
  195.    End
  196.    Begin VB.Label lblVerify 
  197.       Height          =   255
  198.       Index           =   1
  199.       Left            =   1800
  200.       TabIndex        =   8
  201.       Top             =   840
  202.       Width           =   1575
  203.    End
  204.    Begin VB.Label lblPoints 
  205.       Height          =   255
  206.       Index           =   1
  207.       Left            =   1800
  208.       TabIndex        =   7
  209.       Top             =   360
  210.       Width           =   1575
  211.    End
  212.    Begin VB.Label lblSegments 
  213.       Height          =   255
  214.       Index           =   1
  215.       Left            =   1800
  216.       TabIndex        =   6
  217.       Top             =   600
  218.       Width           =   1575
  219.    End
  220.    Begin VB.Label lblSegments 
  221.       Height          =   255
  222.       Index           =   0
  223.       Left            =   120
  224.       TabIndex        =   4
  225.       Top             =   600
  226.       Width           =   1575
  227.    End
  228.    Begin VB.Label lblPoints 
  229.       Height          =   255
  230.       Index           =   0
  231.       Left            =   120
  232.       TabIndex        =   3
  233.       Top             =   360
  234.       Width           =   1575
  235.    End
  236.    Begin VB.Label lblVerify 
  237.       Height          =   255
  238.       Index           =   0
  239.       Left            =   120
  240.       TabIndex        =   1
  241.       Top             =   840
  242.       Width           =   1575
  243.    End
  244.    Begin VB.Label Label1 
  245.       Caption         =   "Tetrahedron"
  246.       Height          =   255
  247.       Index           =   0
  248.       Left            =   120
  249.       TabIndex        =   0
  250.       Top             =   120
  251.       Width           =   1575
  252.    End
  253. Attribute VB_Name = "frmSolids"
  254. Attribute VB_GlobalNameSpace = False
  255. Attribute VB_Creatable = False
  256. Attribute VB_PredeclaredId = True
  257. Attribute VB_Exposed = False
  258. Option Explicit
  259. ' One polyline per solid.
  260. Private Const MAX_SOLID = 4
  261. Private Polylines(0 To MAX_SOLID) As Polyline3d
  262. ' Location of viewing eye.
  263. Private EyeR As Single
  264. Private EyeTheta As Single
  265. Private EyePhi As Single
  266. ' Location of focus point.
  267. Private Const FocusX = 0#
  268. Private Const FocusY = 0#
  269. Private Const FocusZ = 0#
  270. Private Projector(1 To 4, 1 To 4) As Single
  271. ' Project and draw the data.
  272. Private Sub DrawData()
  273. Dim i As Integer
  274.     ' Display the solids.
  275.     For i = 0 To MAX_SOLID
  276.         ' Transform the data for this solid.
  277.         Polylines(i).ApplyFull Projector
  278.         ' Draw the solid.
  279.         picCanvas(i).Cls
  280.         Polylines(i).Draw picCanvas(i)
  281.         picCanvas(i).Refresh
  282.     Next i
  283. End Sub
  284. ' Calculate and verify the points.
  285. Private Sub Form_Load()
  286. Dim i As Integer
  287.     ' Make the data.
  288.     GetTetrahedron Polylines(0)
  289.     GetCube Polylines(1)
  290.     GetOctahedron Polylines(2)
  291.     GetDodecahedron Polylines(3)
  292.     GetIcosahedron Polylines(4)
  293.     ' Verify and display the data.
  294.     For i = 0 To MAX_SOLID
  295.         If Polylines(i).SolidOk() Then
  296.             lblVerify(i).Caption = "Verification: Ok"
  297.         Else
  298.             lblVerify(i).Caption = "Verification: Error"
  299.         End If
  300.         lblPoints(i).Caption = Format$(Polylines(i).NumPoints) & " points"
  301.         lblSegments(i).Caption = Format$(Polylines(i).NumSegs) & " segments"
  302.     Next i
  303.     ' Initialize the eye position.
  304.     EyeR = 5
  305.     EyeTheta = PI * 0.4
  306.     EyePhi = PI * 0.1
  307.     ' Initialize the projection transformation.
  308.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  309.     ' Draw the data.
  310.     DrawData
  311. End Sub
  312. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  313. Const Dtheta = PI / 20
  314.     Select Case KeyCode
  315.         Case vbKeyLeft
  316.             EyeTheta = EyeTheta - Dtheta
  317.         Case vbKeyRight
  318.             EyeTheta = EyeTheta + Dtheta
  319.         Case vbKeyUp
  320.             EyePhi = EyePhi - Dtheta
  321.         Case vbKeyDown
  322.             EyePhi = EyePhi + Dtheta
  323.         Case Else
  324.             Exit Sub
  325.     End Select
  326.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  327.     DrawData
  328. End Sub
  329.